<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<ul class="contact-list"  style="margin-top:5px;">
	
	<c:forEach var="contact" items="${contact.contactList}">
		<c:set var="hasDetail" value="false" />
		<c:if  test="${(!empty contact.workPhone) || (!empty contact.cellPhone) || (!empty contact.email) || (!empty contact.altEmail) || (!empty contact.url)}">
			<c:set var="hasDetail" value="true" />
		</c:if>
		
		<li>
			<div class="cmd-tree-item-wrapper ui-corner-all">
				<c:if  test="${!empty contact.tagId}">
					<c:choose>
						<c:when test="${contact.tagId == 1}">
							<div class="cmd-tree-item-section cmd-tree-item-label-red">Agency</div>
						</c:when>
						<c:when test="${contact.tagId == 2}">
							<div class="cmd-tree-item-section cmd-tree-item-label-blue">Rep</div>
						</c:when>
						<c:when test="${contact.tagId == 3}">
							<div class="cmd-tree-item-section cmd-tree-item-label-orange">Job</div>
						</c:when>
						<c:when test="${contact.tagId == 4}">
							<div class="cmd-tree-item-section cmd-tree-item-label-green">Contact</div>
						</c:when>
					</c:choose>
				</c:if>
				
				<div class="cmd-tree-item-section cmd-tree-item-content">
					<c:url var="commURL" value="/comm">
						<c:param name="contactId">${contact.id}</c:param>
					</c:url>
					<a href="${commURL}" style="color:black;text-decoration: none;" title="Edit/Add communique">
					${contact.lastName}<c:if  test="${!empty contact.firstName}">, ${contact.firstName}</c:if>&nbsp;
					</a>
				</div>
				<div class="cmd-tree-item-menu cmd-tree-item-section" >
					<%/* Delete */%>
					<c:if  test="${empty contact.contactList}">
						<c:url var="deleteContactURL" value="/contact/delete">
							<c:param name="contactId">${contact.id}</c:param>
						</c:url>
						<a href="${deleteContactURL}" class="right-border"><span class="ui-icon ui-icon-closethick ui-corner-all" title="Delete"></span></a>
					</c:if>
					 
					<%/* New */%>
					<c:url var="newContactURL" value="/contact">
						<c:param name="contactParentId">${contact.id}</c:param>
					</c:url>
					<a href="${newContactURL}" class="right-border"><span class="ui-icon ui-icon-document ui-corner-all" title="New"></span></a>
					
					<%/* Edit */%>
					<c:url var="editContactURL" value="/contact">
						<c:param name="contactId">${contact.id}</c:param>
					</c:url>
					<a href="${editContactURL}"><span class="ui-icon ui-icon-pencil ui-corner-all" title="Edit"></span></a>
					
					<%/* Detail */%>
					<c:if  test="${hasDetail}">
						<a href="javascript:showDetail(${contact.id})" class="left-border"><span id="detail-button${contact.id}" class="ui-icon ui-icon-arrowthick-1-s ui-corner-all" title="Details"></span></a>
					</c:if>
					
				</div>
			</div>
			<c:if  test="${hasDetail}">
				<br/>
				<div id="detail-table-holder${contact.id}" class="detail-table-holder">
					
					<table id="detail-table${contact.id}" class="detail-table">
					<c:if  test="${!empty contact.workPhone}">
						<tr><td>Work Phone</td><td>${contact.workPhone}</td></tr>
					</c:if>
					<c:if  test="${!empty contact.cellPhone}">
						<tr><td>Cell Phone</td><td>${contact.cellPhone}</td></tr>
					</c:if>
					<c:if  test="${!empty contact.email}">
						<tr><td>Email</td><td>${contact.email}</td></tr>
					</c:if>
					<c:if  test="${!empty contact.altEmail}">
						<tr><td>Alt. Email</td><td>${contact.altEmail}</td></tr>
					</c:if>
					<c:if  test="${!empty contact.url}">
						<tr><td>URL</td><td>${contact.url}</td></tr>
					</c:if>
					</table>
					
				</div>
			</c:if>
			<script>
			$("#detail-table-holder${contact.id}").data("dwtag","off");
			$("#detail-table-holder${contact.id}").hide();
			</script>
			<c:if  test="${!empty contact.contactList}"> 
				<c:set var="contact" value="${contact}" scope="request"/>
				<jsp:include page="contact_inner_loop.jsp"/>
			</c:if>
		</li>
	
	</c:forEach>
	
</ul>